<template>
	<!-- 优惠券 -->
	<view class="page">
			<view class="typeArr">
				<text :class="activeIndex == item.id ? 'activeText' :'' "  v-for="(item,index) in typeArr" :key="index" @click="changeType(item.id)">{{item.name}}</text>
			</view>
			<scroll-view  scroll-y class="arr"  @scrolltolower="scrolltolower">
				<view class="arrItem" v-for="(item,index) in couponsArr" :key="index">
					<view :class="activeIndex == 1 ? 'cover' : 'cover grayCover'" >
						<view class="price">
							<text>￥</text>{{item.belongs_to_coupon.deduct}}
						</view>
						<view class="tips">
							{{item.belongs_to_coupon.name}}
						</view>
					</view>
					<view class="content">
						<view class="box">
							<text>{{item.api_limit}}</text>
							<view class="time">
								有效期至 {{item.time_end}}
							</view>
						</view>
						<text  @click="goShop()" :class="activeIndex == 1 ? 'btn' : 'btn grayBtn'" >{{activeIndex==1 ? '去使用' : activeIndex==2 ? '已过期' : '已使用' }}</text>
					</view>
				</view>
				<noMore v-if="!couponsArr.length"></noMore>
			</scroll-view>
	</view>
</template>

<script>
	import noMore from '@/components/noMore/noMore.vue'
	export default {
		data() {
			return {
				typeArr:[
					{
						name:'待使用',
						id: 1,
					},
					{
						name:'已使用',
						id: 3,
					},
					{
						name:'已过期',
						id: 2,
					},
				],
				activeIndex : 1,
				page: 1,
				couponsArr:[]
			};
		},
		methods:{
			goShop(){
				if(this.activeIndex == 1){
					uni.switchTab({
						url:'/pages/tabShop/index'
					})
				}
			},
			scrolltolower(){
				this.page++
				this.getCouponsArr()
			},
			changeType(_index){
				this.page = 1
				this.activeIndex = _index
				this.getCouponsArr()
			},
			getCouponsArr(){
				this.myHttp({
					data:{
						type : 3,
						route : 'coupon.member-coupon.coupons-of-member-by-status-v2',
						status_request : this.activeIndex ,
						page : this.page
					}
				}).then((res)=>{
					if(res.result== '1'){
						if(this.page==1){
							this.couponsArr = []
						}
						this.couponsArr = this.couponsArr.concat(res.data.data) 
					}
				})
			},
		},
		components:{
			noMore
		},
		onLoad() {
			this.getCouponsArr()
		}
	}
</script>

<style lang="scss" scoped>
	.page{
		background-color: #F8F8F8;
		height: 100vh;
		.typeArr{
			background-color: #fff;
			display: flex;
			width: 100%;
			height: 80rpx;
			align-items: center;
			text{
				flex: 1;
				font-size: 28rpx;
				font-family: PingFang SC;
				color: #000000;
				display: flex;
				justify-content: center;
				
			}
			.activeText{
				color: #FF5113;
				position: relative;
				&:after{
					content: '';
					position: absolute;
					bottom: -60%;
					width: 90rpx;
					height: 8rpx;
					background: #FF5113;
					border-radius: 4rpx;
				}
			}
		}
	
		.arr{
			height: calc( 100vh - 80rpx );
			// display: flex;
			// align-items: center;
			// flex-direction: column;
			// width: 100%;
			padding: 16rpx 25rpx;
			.arrItem{
				width: 700rpx;
				height: 178rpx;
				background: #FFFFFF;
				border-radius: 10px;
				display: flex;
				margin-bottom: 18rpx;
				.grayCover{
					background: linear-gradient(0deg, #B8B6B6, #989797) !important;
				}
				.cover{
					width: 193rpx;
					height: 178rpx;
					background: linear-gradient(0deg, #FF5113, #FF6731);
					border-radius: 10rpx 0 0 10rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					color: #fff;
					position: relative;
					:after{
						content: '';
						position: absolute;
						right: 0;
						top: 50%;
						transform: translate(50%,-50%);
						width: 40rpx;
						height: 40rpx;
						background-color: #fff;
						border-radius: 50%;
					}
					.price{
						font-weight: 600;
						font-size: 55rpx;
						font-family: PingFang SC;
						text{
							font-size: 28rpx;
							font-weight: 400;
						}
					}
					.tips{
						font-size: 24rpx;
						font-family: PingFang SC;
						margin-bottom: 20rpx;
						margin-top: 15rpx;
						width: 100%;
						padding: 0 20rpx;
						text-align: center;
					}
				}
				
				.content{
					flex: 1;
					display: flex;
					align-items: center;
					.box{
						flex: 1;
						display: flex;
						flex-direction: column;
						justify-content: center;
						padding-left: 50rpx;
						text{
							font-size: 28rpx;
							font-family: PingFang SC;
							font-weight: 600;
							margin-bottom: 20rpx;
							color: #000000;
						}
						.time{
							font-size: 22rpx;
							font-family: PingFang SC;
							font-weight: 400;
							color: #888787;
						}
					}
					.btn{
						width: 94rpx;
						height: 38rpx;
						border: 2rpx solid #FF5113;
						border-radius: 10rpx;
						color: #FF5113;
						margin-right: 23rpx;
						font-size: 21rpx;
						display: grid;
						place-items: center;
					}
					.grayBtn{
						background-color: #B8B6B6;
						border: 0;
						color: #fff;
					}
					
					
				}
			}
		}
	}

</style>
